package org.serverct.finalfight.game.hadesgame.events;

import org.bukkit.Bukkit;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.serverct.finalfight.game.hadesgame.EventType;
import org.serverct.finalfight.internal.game.basic.BasicGame;
import org.serverct.finalfight.internal.game.hadesgame.InstantEvent;

import java.util.UUID;

public class BrokenInventory extends InstantEvent {

    public BrokenInventory(BasicGame game, EventType type) {
        super(game, type);
    }

    @Override
    public void execute() {
        for (UUID uuid : this.game.players.keySet()) {
            Player player = Bukkit.getPlayer(uuid);
            if (!this.game.isAlive(player)) {
                continue;
            }
            PlayerInventory inv = player.getInventory();
            for (int i = 0; i < inv.getSize(); i++) {
                ItemStack item = inv.getItem(i);
                if (item != null) {
                    Item drop = player.getWorld().dropItemNaturally(player.getLocation(), item);
                    drop.setPickupDelay(60);
                    inv.setItem(i, null);
                }
            }
        }
    }
}
